//package com.bacel.nb.product.web.controller;
//
//import com.alibaba.fastjson.JSONArray;
//import com.bacel.nb.product.core.dto.TotalModuleDto;
//import com.bacel.nb.product.core.service.ILogsService;
//import com.bacel.nb.product.core.service.ISysmoduleService;
//import com.bacel.nb.product.web.template.ViewModel.FreeMarkerView;
//import com.bacel.nb.product.web.util.StringUtilis;
//import com.bacel.nb.product.web.util.WebUtilify;
//import com.bacel.nb.product.web.util.mysqlHelper;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.web.bind.annotation.RequestMapping;
//import org.springframework.web.bind.annotation.RequestMethod;
//import org.springframework.web.bind.annotation.RestController;
//import org.springframework.web.servlet.ModelAndView;
//
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpSession;
//import java.util.*;
//
///**
// * Created by Bacel on 2017/7/18.
// */
//@RestController
//@RequestMapping(value = "/sysmanage/total", produces = "text/html;charset=UTF-8")
//public class totalController {
//
//    @Autowired
//    ISysmoduleService sysmoduleService;
//    //设置终端,配置信息
//    @RequestMapping(value = "/list_data", method = RequestMethod.GET)
//    public ModelAndView list_data(final HttpSession session, final HttpServletRequest request)
//            throws Exception {
//        String errstr = "";
//        String date_start = request.getParameter("date_start");
//        String date_end = request.getParameter("date_end");
//
//        String strWhere = " where 1=1";
//        if (date_start != null && date_start.length() > 0) {
//            strWhere += " and TO_DAYS('" + date_start + "') - TO_DAYS(createdate) <= 0";
//        }
//        if (date_end != null && date_end.length() > 0) {
//            strWhere += " and TO_DAYS('" + date_end + "') - TO_DAYS(createdate) >= 0";
//        }
//
//        String sql = "SELECT  COUNT(1)num,DATE_FORMAT(createdate,'%y-%m-%d') as  datestr from devicedata " + strWhere + " group by DATE_FORMAT(createdate,'%y-%m-%d')";
//        sql += " ORDER BY datestr ASC";
//
//        List<TotalModuleDto> totalseries = new ArrayList<>();
//
//        TotalModuleDto moduleDto1 = new TotalModuleDto();
//        moduleDto1.name = "正常";
//        moduleDto1.color = "#3366FF";
//        TotalModuleDto moduleDto2 = new TotalModuleDto();
//        moduleDto2.name = "无效";
//        moduleDto2.color = "#FF3333";
//        List<String> categories = new ArrayList<>();
//        mysqlHelper helper = new mysqlHelper();
//        List<Map<String, Object>> mapList = helper.returnMultipleResult(sql, null);
//        if (mapList != null) {
//            for (int i = 0; i < mapList.size(); i++) {
//                Map<String, Object> map = mapList.get(i);
//                categories.add(map.get("datestr").toString());
//                moduleDto1.data.add(StringUtilis.toFloat(map.get("num").toString()));
//                moduleDto2.data.add(StringUtilis.toFloat(map.get("num").toString()) - 3);
//            }
//        }
//        totalseries.add(moduleDto1);
//        totalseries.add(moduleDto2);
//        String path = request.getContextPath();
//        String menulist = WebUtilify.BuildMenuinfo(path,sysmoduleService);
//        // 显示首页
//        ModelAndView mav = new FreeMarkerView("total/list_data", "统计", path, menulist, session);
//        mav.addObject("date_start", date_start);
//        mav.addObject("date_end", date_end);
//        mav.addObject("categories", JSONArray.toJSONString(categories));
//        mav.addObject("totalseries", JSONArray.toJSONString(totalseries));
//        return mav;
//    }
//
//    @RequestMapping(value = "/list_dataapp", method = RequestMethod.GET)
//    public ModelAndView list_dataapp(final HttpSession session, final HttpServletRequest request)
//            throws Exception {
//        String errstr = "";
//        String date_start = request.getParameter("date_start");
//        String date_end = request.getParameter("date_end");
//        String app = request.getParameter("app");
//        String strWhere = " where  1=1";
//        if (date_start != null && date_start.length() > 0) {
//            strWhere += " and TO_DAYS('" + date_start + "') - TO_DAYS(createdate) <= 0";
//        }
//        if (date_end != null && date_end.length() > 0) {
//            strWhere += " and TO_DAYS('" + date_end + "') - TO_DAYS(createdate) >= 0";
//        }
//        if (app != null && app.length() > 0) {
//            strWhere += " and app='" + app + "'";
//        }
//        String sql = "SELECT  COUNT(1)num,app,DATE_FORMAT(createdate,'%y-%m-%d') as  datestr from devicedata " + strWhere + " group by app,DATE_FORMAT(createdate,'%y-%m-%d')";
//        sql += " ORDER BY app,datestr ASC";
//        List<TotalModuleDto> totalseries = new ArrayList<>();
//
//        TotalModuleDto moduleDto1 = new TotalModuleDto();
//        moduleDto1.name = "正常";
//        moduleDto1.color = "#3366FF";
//        TotalModuleDto moduleDto2 = new TotalModuleDto();
//        moduleDto2.name = "无效";
//        moduleDto2.color = "#FF3333";
//        List<String> categories = new ArrayList<>();
//        mysqlHelper helper = new mysqlHelper();
//        List<Map<String, Object>> mapList = helper.returnMultipleResult(sql, null);
//        if (mapList != null) {
//            for (int i = 0; i < mapList.size(); i++) {
//                Map<String, Object> map = mapList.get(i);
//                categories.add(map.get("datestr").toString());
//                moduleDto1.data.add(StringUtilis.toFloat(map.get("num").toString()));
//                moduleDto2.data.add(StringUtilis.toFloat(map.get("num").toString()) - 3);
//            }
//        }
//        totalseries.add(moduleDto1);
//        totalseries.add(moduleDto2);
//        String path = request.getContextPath();
//        String menulist = WebUtilify.BuildMenuinfo(path,sysmoduleService);
//        // 显示首页
//        ModelAndView mav = new FreeMarkerView("total/list_dataapp", "统计", path, menulist, session);
//        mav.addObject("date_start", date_start);
//        mav.addObject("date_end", date_end);
//        mav.addObject("categories", JSONArray.toJSONString(categories));
//        mav.addObject("totalseries", JSONArray.toJSONString(totalseries));
//        return mav;
//    }
//    @RequestMapping(value = "/list_apporder", method = RequestMethod.GET)
//    public ModelAndView list_apporder(final HttpSession session, final HttpServletRequest request)
//            throws Exception {
//        String errstr = "";
//        String date_start = request.getParameter("date_start");
//        String date_end = request.getParameter("date_end");
//        String app = request.getParameter("app");
//        String strWhere = " where  1=1";
//        if (date_start != null && date_start.length() > 0) {
//            strWhere += " and TO_DAYS('" + date_start + "') - TO_DAYS(createdate) <= 0";
//        }
//        if (date_end != null && date_end.length() > 0) {
//            strWhere += " and TO_DAYS('" + date_end + "') - TO_DAYS(createdate) >= 0";
//        }
//        if (app != null && app.length() > 0) {
//            strWhere += " and app='" + app + "'";
//        }
//        String sql = "SELECT  COUNT(1)num,app,DATE_FORMAT(createdate,'%y-%m-%d') as  datestr from devicedata " + strWhere + " group by app,DATE_FORMAT(createdate,'%y-%m-%d')";
//        sql += " ORDER BY app,datestr ASC";
//        List<TotalModuleDto> totalseries = new ArrayList<>();
//
//        TotalModuleDto moduleDto1 = new TotalModuleDto();
//        moduleDto1.name = "正常";
//        moduleDto1.color = "#3366FF";
//        TotalModuleDto moduleDto2 = new TotalModuleDto();
//        moduleDto2.name = "无效";
//        moduleDto2.color = "#FF3333";
//        List<String> categories = new ArrayList<>();
//        mysqlHelper helper = new mysqlHelper();
//        List<Map<String, Object>> mapList = helper.returnMultipleResult(sql, null);
//        if (mapList != null) {
//            for (int i = 0; i < mapList.size(); i++) {
//                Map<String, Object> map = mapList.get(i);
//                categories.add(map.get("datestr").toString());
//                moduleDto1.data.add(StringUtilis.toFloat(map.get("num").toString()));
//                moduleDto2.data.add(StringUtilis.toFloat(map.get("num").toString()) - 3);
//            }
//        }
//        totalseries.add(moduleDto1);
//        totalseries.add(moduleDto2);
//        String path = request.getContextPath();
//        String menulist = WebUtilify.BuildMenuinfo(path,sysmoduleService);
//        // 显示首页
//        ModelAndView mav = new FreeMarkerView("total/list_apporder", "统计", path, menulist, session);
//        mav.addObject("date_start", date_start);
//        mav.addObject("date_end", date_end);
//        mav.addObject("categories", JSONArray.toJSONString(categories));
//        mav.addObject("totalseries", JSONArray.toJSONString(totalseries));
//        return mav;
//    }
//
//}
